<template>
  <div class="tabbar">
    <ul>
      <li
        v-for="(item, index) in routerList"
        :key="index"
        @click="goAim(item.path)"
      >
        <img
          :src="$route.path.includes(item.path) ? item.selected : item.active"
          alt=""
        />
        <span :class="$route.path.includes(item.path) ? 'chosen' : ''">{{
          item.title
        }}</span>
      </li>
    </ul>
  </div>
</template>
<script>
export default {
  name: "Tabbar",
  data() {
    return {
      routerList: [
        {
          title: "首页",
          path: "home",
          active: "./img/home.png",
          selected: "./img/home-selected.png",
        },
        {
          title: "分类",
          path: "/list",
          active: "./img/class.png",
          selected: "./img/class-selected.png",
        },
        {
          title: "购物车",
          path: "/cart",
          active: "./img/cart.png",
          selected: "./img/cart-selected.png",
        },
        {
          title: "我的",
          path: "/my",
          active: "./img/smile.png",
          selected: "./img/smile-selected.png",
        },
      ],
    };
  },
  methods: {
    goAim(path) {
      if (this.$route.path == path) return false;
      this.$router.push(path);
    },
  },
};
</script>
<style lang="scss" scoped>
.chosen {
  color: red;
}
.tabbar {
  position: fixed;
  left: 0px;
  bottom: 0;
  width: 375px;
  height: 1.2rem;
  background-color: #fff;
}
ul {
  display: flex;
  justify-content: space-around;
  align-items: center;
}
li {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
img {
  width: 0.7rem;
  height: 0.7rem;
}
span {
  font-size: 0.333333rem;
}
</style>